package huoye.shops.huoye.operation.activity;

import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.codeideology.android.AXIFragmentPagerAdapter;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import huoye.shops.R;
import huoye.shops.base.BaseActivity;
import huoye.shops.huoye.mine.fragment.MineFragment;
import huoye.shops.huoye.operation.fragment.ManageEventFragment;
import huoye.shops.utils.StockUtils;

import static huoye.shops.base.BaseFragment.TYPE_START_MANAGE;

public class ManageEventActivity extends BaseActivity {

    @BindView(R.id.base_toolbar_tl)
    TabLayout tl;
    @BindView(R.id.base_toolbar_vp)
    ViewPager vp;
    @BindView(R.id.operation_manage_event_btn_add_event)
    Button btnAddEvent;

    List<Fragment> fragments = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    AXIFragmentPagerAdapter myFragmentPagerAdapter;


    @OnClick(R.id.operation_manage_event_btn_add_event)
    void onAddEventClick(){
        startActivity(BuildEventActivity.class);
    }




    @Override
    protected int getContentViewId() {
        return R.layout.activity_manage_event;
    }

    @Override
    protected void initView(@Nullable Bundle bundle) {
        setTitle("活动管理");

        boolean isBuildEvent = getIntent().getBooleanExtra(TYPE_START_MANAGE, false);
        Log.e("test",isBuildEvent+"");
        if(isBuildEvent){
            btnAddEvent.setVisibility(View.VISIBLE);
        }

        fragments.add(ManageEventFragment.getInstan(ManageEventFragment.TYPE_MANAGE_EVENT_START));
        fragments.add(ManageEventFragment.getInstan(ManageEventFragment.TYPE_MANAGE_EVENT_END));



        titles.add(getString(R.string.operation_event_start));
        titles.add(getString(R.string.operation_event_end));


        StockUtils.reflex(tl);
        myFragmentPagerAdapter = new AXIFragmentPagerAdapter(getSupportFragmentManager(),fragments, titles);
        vp.setAdapter(myFragmentPagerAdapter);
        vp.setOffscreenPageLimit(fragments.size());
        tl.setupWithViewPager(vp);
    }
}
